<?php
/**
 * Description
 *
 * PHP version 7
 *
 * @category Custom
 * @package  Custom
 * @author   ryu <mo5467@126.com>
 * @date     2020-04-29 00:12:04
 * @lastTime 2020-05-01 23:14:12
 * @license  https://opensource.org/licenses/MIT MIT License
 * @link     none
 */
namespace Test\Unit;

use Design\Behavioral\Specification\Item;
use Design\Behavioral\Specification\OrSpecification;
use Design\Behavioral\Specification\AndSpecification;
use Design\Behavioral\Specification\NotSpecification;
use Design\Behavioral\Specification\PriceSpecification;

class SpecificationTest extends \Test\BaseTest
{


    public function testCanOr()
    {
        $spec1 = new PriceSpecification(50, 99);
        $spec2 = new PriceSpecification(101, 150);

        $orSpec = new OrSpecification($spec1, $spec2);

        $this->assertTrue($orSpec->isSatisfiedBy(new Item(51)));
        $this->assertFalse($orSpec->isSatisfiedBy(new Item(100)));
        $this->assertFalse($orSpec->isSatisfiedBy(new Item(151)));

    }//end testCanOr()


    public function testCanAnd()
    {
        $spec1 = new PriceSpecification(50, 120);
        $spec2 = new PriceSpecification(70, 150);

        $andSpec = new AndSpecification($spec1, $spec2);

        $this->assertTrue($andSpec->isSatisfiedBy(new Item(100)));
        $this->assertFalse($andSpec->isSatisfiedBy(new Item(60)));
        $this->assertFalse($andSpec->isSatisfiedBy(new Item(151)));

    }//end testCanAnd()


    public function testCanNot()
    {
        $spec = new PriceSpecification(50, 99);

        $notSpec = new NotSpecification($spec);

        $this->assertTrue($notSpec->isSatisfiedBy(new Item(100)));
        $this->assertFalse($notSpec->isSatisfiedBy(new Item(75)));

    }//end testCanNot()


}//end class
